﻿/**
 * \brief 线程组定义
 * \file CThreadGroup.h
 */
#ifndef __CTHREAD__GROUP__H
#define __CTHREAD__GROUP__H

#include <vector>
#include "CThread.h"

class CThreadGroup
{
	public:
		CThreadGroup()
		{}

		~CThreadGroup()
		{
			_thread_iter iter = this->_M_list.begin();
			for(; iter != this->_M_list.end(); ++iter)
			{
				if(*iter) delete *iter;
			}

			this->_M_list.clear();
		}

	public:
		/// 以索引得到线程指针
		CThread* getByIdx(size_t idx)
		{
			if(this->_M_list.size() > idx)
			{
				return this->_M_list[idx];
			}

			return NULL;
		}

		/// 得到线程个数
		size_t getThreadNum()
		{
			return this->_M_list.size();
		}

		/// 加入线程
		bool addThread(CThread* pThread)
		{
			if(pThread)
			{
				this->_M_list.push_back(pThread);
				return true;
			}

			return false;
		}

	private:
		typedef std::vector<CThread*> _thread_vec;
		typedef _thread_vec::iterator _thread_iter;
		_thread_vec _M_list;			/// 线程列表
};

#endif	/// __CTHREAD__GROUP__H
